package com.mage.servlet;

import com.mage.bean.PageBean;
import com.mage.bean.User;
import com.mage.dao.UserDao;
import com.mage.dao.impl.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/UserInfoServlet")
public class UserInfoServlet  extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public UserInfoServlet() {
        super();
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            //1. 获取需要显示的页码数
            int currentPage = 1;
            if(request.getParameter("currentPage")!=null) {
                currentPage =Integer.parseInt( request.getParameter("currentPage"));
            }
            int userid = Integer.parseInt(request.getParameter("userid"));

            //2. 根据指定的页数，去获取该页的数据回来
            UserDao service = new UserDaoImpl();
            User user = service.findUserById(userid);
            request.setAttribute("user", user);
            //3. 跳转界面。
            request.getRequestDispatcher("/Super/User_userinfo.jsp").forward(request, response);
        }catch (Exception e) {
            // TODO: handle exception
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
